package com.smartcruise.report.reportRecord;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.smartcruise.R;
import com.smartcruise.base.BaseTitleActivity;
import com.smartcruise.base.RefreshContract;
import com.smartcruise.base.RefreshSimpleImp;
import com.smartcruise.base.TitleBuilder;
import com.smartcruise.util.IntentUtils;

import butterknife.BindView;

/**
 * Created by FengChaoQun
 * on 2018/3/5 0005
 * 通报记录
 */

public class ReportRecordActivity extends BaseTitleActivity implements RefreshContract.View {
    @BindView(R.id.listView)
    ListView listView;
    @BindView(R.id.swipeRefreshLayout)
    SmartRefreshLayout swipeRefreshLayout;
    @BindView(R.id.emptyView)
    TextView emptyView;

    private String cruiseId;//对应巡航任务的id

    private RefreshContract.Presenter mPresenter;
    protected RefreshContract.RefreshInterface refreshInterface;

    /**
     * description:打开通报记录界面
     *
     * @param cruiseId 巡航任务的id 空的时候表示查看所有的通报 不为空的时候表示查看对应巡航任务的通报
     */

    public static void start(Context context, String cruiseId) {
        Intent intent = new Intent(context, ReportRecordActivity.class);
        if (!TextUtils.isEmpty(cruiseId)) {
            intent.putExtra(IntentUtils.ID, cruiseId);
        }
        context.startActivity(intent);
    }

    @Override
    protected void init() {

        refreshInterface = new RefreshSimpleImp(swipeRefreshLayout);
        refreshInterface.setOnRefreshListener(new RefreshContract.OnRefreshListener() {
            @Override
            public void onRefresh(RefreshContract.RefreshInterface refreshInterface) {
                mPresenter.refresh();
            }
        });
        refreshInterface.setOnLoadMoreListener(new RefreshContract.OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshContract.RefreshInterface refreshInterface) {
                mPresenter.loadMore();
            }
        });

        listView.setEmptyView(emptyView);
        listView.setPadding(0, 10, 0, 0);
        listView.setDividerHeight(2);
        cruiseId = getIntent().getStringExtra(IntentUtils.ID);
        mPresenter = new ReportPresenterImp(this, cruiseId);
        mPresenter.start();

    }

    @Override
    protected int getContentLayout() {
        return R.layout.util_refresh_list;
    }

    @Override
    protected TitleBuilder getTitleBuilder() {
        return TitleBuilder.create(true, getString(R.string.reportRecord));
    }

    /**
     * description:获取刷新组件
     */
    @Override
    public RefreshContract.RefreshInterface getRefresh() {
        return refreshInterface;
    }

    @Override
    public void setData(BaseAdapter baseAdapter) {
        listView.setAdapter(baseAdapter);
    }

}
